#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Data  :     2020/5/8 下午1:43
--------------------------------------
"""
import requests


def gettoken(**kwargs):
    """
    获取token
    :return:
    """

    if kwargs['env'] is None:
        url = kwargs['url']
    else:
        url = "http://" + kwargs['env'] + "." + kwargs['url'][7:]

    data = {
        'username': kwargs['username'],
        'password': kwargs['password']
    }
    res = requests.post(url=url, data=data)

    return res.json()['data']['accesstoken']


if __name__ == '__main__':
    data = {
        'url': 'httpL//api.data.childfit.cn/organize/person/login',
        'username': 'sjch123456',
        'password': '123456',
        'env': None
    }

    print(gettoken(url='http://api.data.childfit.cn/organize/person/login', username='sjch123456', password='123456',
                   env='test'))
